import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';

import error from '@dfeidao/atom-web/msgbox/error';

import get from '@dfeidao/atom-web/local/get';
import { productid } from '../../atom/config';

import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';



import success from '@dfeidao/atom-web/msgbox/success';

/** 保存  */
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// todo
	const flags = get(fd, 'flags');
	const knowledge_no1 = get(fd, 'knowledge_no');
	const knowledge_name1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="knowledge_name"]');
	const knowledge_name2 = knowledge_name1.value;
	const knowledge_explain1 = fd.data.node.querySelector<HTMLInputElement>('[data-id="knowledge_explain"]');
	const knowledge_explain2 = knowledge_explain1.value;
	const res = await nodejs<{ code: 0 | 1; result: string }>('knowledge-base/zj-000004/s001', {
		filter: {
			knowledge_no: knowledge_no1,
			knowledge_name: knowledge_name2,
			knowledge_explain: knowledge_explain2,
			productid
		}
	});
	if (res.code === 1) {
		success('编辑成功');
		const edit = fd.data.node.querySelector<HTMLDivElement>('[data-id="editblock"]');
		set_node_cls(edit, 'display-n', true);
		fire('zj-000003', 'a002');
		if (flags === 2) {
			fire('zj-000001', 'a007');
		} if (flags === 3) {
			fire('zj-000001', 'a009');
		} if (flags === 4) {
			fire('zj-000001', 'a011');
		}
	} else {
		error('编辑失败');
	}
}
